package cg.cmm.base.utils;

import cg.cmm.base.constant.Constant;
import org.slf4j.MDC;

import java.util.UUID;

/**
 * 全局链路id生成工具类
 *
 * @author chong
 * @version 1.0
 */
public class RequestIdUtils {

    public static void setRequestId() {
        MDC.put(Constant.TRACE_ID, UUID.randomUUID().toString());
    }

    public static void setRequestId(String requestId) {
        MDC.put(Constant.TRACE_ID, requestId);
    }

    public static String getRequestId() {
        return MDC.get(Constant.TRACE_ID);
    }

    public static void clear() {
        MDC.clear();
    }
}
